package com.helmlabs.grouper.accounts.service;

import java.util.List;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

import com.helmlabs.grouper.accounts.model.Company;
import com.helmlabs.grouper.accounts.model.Role;
import com.helmlabs.grouper.accounts.model.UserProfile;

@WebService
public interface AccountManager {
	

	/**
	 * Get a user profile based on the id of 
	 * the parameter.
	 * @param id
	 * @return
	 */
	public UserProfile getUserProfile(Long id);
	
	/**
	 * Retrieve a list of user profiles that is
	 * good for paging.  
	 * @param page
	 * @param pageSize
	 * @param sort
	 * @param desc
	 * @return
	 */
	public List<UserProfile> getUserProfiles(int page, int pageSize, String sort, String desc);
	public UserProfile getUserProfileByUsername(String username);
	public UserProfile saveUserProfile(UserProfile userProfile);
	
	/**
	 * Determine if the user is a member of a specific role.
	 * If the recursive boolean is true, then a search will
	 * be done to see if the user is in a child role of the 
	 * requested role id.
	 * 
	 * @param userid
	 * @param roleid
	 * @param recursive
	 * @return
	 */
	@WebMethod public boolean isUserMemberOfRole(
			@WebParam(name="userid") Long userid, 
			@WebParam(name="roleid") Long roleid, 
			@WebParam(name="recursive") boolean recursive
			);
	
	/**
	 * Check to see if the user is a member
	 * of any of the roles in a given list
	 * of Role identifier numbers
	 * @param userid
	 * @param roleids
	 * @param recursive
	 * @return
	 */
	@WebMethod public boolean isUserMemberOfAnyRoles(
			@WebParam(name="userid") Long userid,
			@WebParam(name="roleid") List<Long> roleids,
			@WebParam(name="recursive") boolean recursive
			);
	
	/**
	 * Check to see if the user is a member of all
	 * the roles in a given list of role id numbers
	 * @param userid
	 * @param roleids
	 * @param recursive
	 * @return
	 */
	@WebMethod public boolean isUserMemberOfAllRoles(
			@WebParam(name="userid") Long userid, 
			@WebParam(name="roleid") List<Long> roleids,
			@WebParam(name="recursive") boolean recursive
			);
	
	
	/**
	 * Determine if a company is actively in a specific role.
	 * if the recursive boolean is true, then a search will
	 * be done to see if the user is in a parent role of the 
	 * requested role id
	 * @param companyid
	 * @param roleid
	 * @param recursive
	 * @return
	 */
	@WebMethod public boolean isCompanyMemberOfRole(
			@WebParam(name="companyid") Long companyid, 
			@WebParam(name="roleid") Long roleid, 
			@WebParam(name="recursive") boolean recursive
			);
	
	/**
	 * Return all the active employees for the company
	 * @param companyid
	 * @return
	 */
	@WebMethod public List<UserProfile> getEmployeesByCompanyId(
			@WebParam(name="companyid") Long companyid
			);
	
	public boolean activateUserInRole(Long userid, Long roleid);
	public boolean deactivateUserOutOfRole(Long userid, Long roleid);
	
	/**
	 * Retrieve all the roles for a user by 
	 * the user identifier. 
	 * @param parentid
	 * @return
	 */
	public List<Role> getUserRolesByParent(Long parentid);
	
	/**
	 * Get all the roles that can be assigned to a company
	 * by the ID of the parent.  This is useful when building
	 * a roles tree. To receive the root parent roles, 
	 * keep the parentid null.
	 * 
	 * @param parentid
	 * @return List com.helmlabs.grouper.accounts.model.Role
	 */
	public List<Role> getCompanyRolesByParent(Long parentid);
	
	/**
	 * Get a company by the id specified in the parameters.
	 * @param id
	 * @return com.helmlabs.grouper.accounts.model.Company
	 */
	@WebMethod public Company getCompanyById(
			@WebParam(name="id") Long id
			);
	
	@WebMethod
	public List<Company> getCompanies(
			@WebParam(name="page") int page,
			@WebParam(name="pageSize") int pageSize,
			@WebParam(name="sort") String sort,
			@WebParam(name="dir") String direction
			);
	
	/**
	 * Get the company that the user is most currently associated
	 * with.
	 * @param id
	 * @return
	 */
	@WebMethod public Company getCurrentCompanyByUserId(@WebParam(name="id")Long id);
	
	/**
	 * Get the user account of the individual that is 
	 * currently logged into the system.
	 * @return com.helmlabs.grouper.accounts.model.UserProfile
	 */
	public UserProfile getCurrentUser();

}
